package 网络通信2;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.io.Writer;
import java.io.OutputStreamWriter;


public class Client {
	public static void main(String[] args) throws Exception
	{
		System.out.println("客户端启动了");
		Scanner sc=new Scanner(System.in);
		InetAddress ia=InetAddress.getLocalHost();
		//1.创建socket对象，用来接通管道
		Socket socket=new Socket(ia,8888);
		//2.向服务端发送数据
		OutputStream os=socket.getOutputStream();
		DataOutputStream dos=new DataOutputStream(os);
		while(true) {
			System.out.println("请输入");
		String ss=sc.nextLine();
		if("exit".equals(ss))
		{
			System.out.println("退出成功");
			os.close();
			socket.close();
			break;
		}
		dos.writeUTF(ss);
		}
	}
}                                                             